﻿using System;

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

using SmlEngine;

namespace SmlEngine.Sprites.Base
{
    /// <summary>
    /// Provides functionality for creating scrolling background layers.
    /// </summary>
    public sealed class BackgroundLayer
    {
        /// <summary>
        /// Gets or sets the image used in the background layer.
        /// </summary>
        public Texture2D Graphics { get; set; }

        /// <summary>
        /// Gets or sets the section the background layer is located in.
        /// </summary>
        public int Section { get; set; }

        /// <summary>
        /// Gets or sets how fast the background layer scrolls relative to the other layers. 
        /// Vector2.One will scroll at the same speed. Used in conjunction with ScrollType.
        /// </summary>
        public Vector2 ScrollSpeed { get; set; }

        /// <summary>
        /// Gets or sets how the background layer scrolls relative to the other layers.
        /// </summary>
        public ScrollType ScrollType { get; set; }

        /// <summary>
        /// Gets or sets how much the background layer is offet relative to the camera.
        /// </summary>
        public Vector2 Offset { get; set; }

        public BackgroundLayer() { }

        public BackgroundLayer(Texture2D graphics, int section, Vector2 speed, ScrollType type)
        {
            Graphics = graphics;
            Section = section;
            ScrollSpeed = speed;
            ScrollType = type;
        }

        public BackgroundLayer Clone()
        {
            return this;
        }

        public void Draw(SpriteBatch spriteBatch)
        {
            int x = (int)Offset.X;
            int y = (int)Offset.Y;

            spriteBatch.Draw(Graphics, Vector2.Zero, new Rectangle(x, y, Graphics.Width, Graphics.Height), Color.White);
        }
    }
}
